package com.wgts.wgts.mvp.view.activity.guessing;

import android.content.Context;
import android.support.annotation.NonNull;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.FrameLayout;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.wgts.wgts.R;
import com.wgts.wgts.control.recycleview.CustomLineaLayoutManager;
import com.wgts.wgts.netmodle.resp.GuessingListEntity;
import com.wgts.wgts.tools.Tools;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

/*
 *
 *
 *   data:2018/9/159:13
 *
 */public class GuessingRecycleAdapter extends RecyclerView.Adapter<GuessingRecycleAdapter.ViewHold> {
    private int lastH;
    private List<GuessingListEntity> data;
    private Context context;
    private GuessingChildRecycleAdapter adapter;

    public GuessingRecycleAdapter(List<GuessingListEntity> data, Context context, int lastH) {
        this.data = data;
        this.context = context;
        this.lastH = lastH;
    }

    @NonNull
    @Override
    public ViewHold onCreateViewHolder(@NonNull ViewGroup viewGroup, int i) {
        View view = LayoutInflater.from(context)
                .inflate(R.layout.guessing_recycle_item, viewGroup, false);
        return new ViewHold(view);
    }

    @Override
    public void onBindViewHolder(@NonNull ViewHold viewHold, int i) {
        //判断最后一个view，解决最后一个订单展示不全
        if (i == data.size() - 1) {
            viewHold.itemView.setLayoutParams(Tools.setViewMargin(viewHold.itemView,true,0,0,0,130));
            if (viewHold.itemView.getHeight() < lastH) {
                FrameLayout.LayoutParams params = new FrameLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,
                        LinearLayout.LayoutParams.MATCH_PARENT);
                params.height = lastH;
                viewHold.itemView.setLayoutParams(params);
            }
        }else {
            viewHold.itemView.setLayoutParams(Tools.setViewMargin(viewHold.itemView,true,0,0,0,0));
        }
        viewHold.guessingRecycleTitle.setText(data.get(i).roundName + "人场");
        CustomLineaLayoutManager lineaLayoutManager = new CustomLineaLayoutManager(context);
        lineaLayoutManager.setScrollEnabled(false);
        viewHold.guessingChildRecycle.setLayoutManager(lineaLayoutManager);
        viewHold.guessingChildRecycle.setNestedScrollingEnabled(false);
        adapter = new GuessingChildRecycleAdapter(context, data.get(i).list);
        viewHold.guessingChildRecycle.setAdapter(adapter);
    }

    @Override
    public int getItemCount() {
        return data.size();
    }

    public class ViewHold extends RecyclerView.ViewHolder {
        @BindView(R.id.guessing_recycle_title)
        TextView guessingRecycleTitle;
        @BindView(R.id.guessing_child_recycle)
        RecyclerView guessingChildRecycle;
        public View itemView;
        public ViewHold(@NonNull View itemView) {
            super(itemView);
            ButterKnife.bind(this, itemView);
            this.itemView = itemView;
        }
    }


}
